﻿using System.Text;

namespace _52_C_生成随机数Random
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Random random = new Random();
            //int num = random.Next(10);
            //Console.WriteLine(num);

            //int num1 = random.Next(0, 10);
            //Console.WriteLine(num1);

            //double dob = random.NextDouble();
            //Console.WriteLine($"{dob,0:N3}");//保留3位

            Random random = new Random(Guid.NewGuid().GetHashCode());//使其更加随机
            //int num = random.Next(100);
            //Console.WriteLine(num);

            //byte[] buffer = new byte[5];
            //random.NextBytes(buffer);
            //foreach (byte b in buffer)
            //{
            //    Console.WriteLine(b);
            //}


            string str2 = "abcdefghijklmnopqrstuvwxyz";
            //StringBuilder sb = new StringBuilder();

            //for (int i = 0; i < 6; i++) {
            //    Console.WriteLine(str2[random.Next(str2.Length)]);
            //}
            ////
            //Console.WriteLine("-----");
            //while (sb.Length<8)
            //{
            //    sb.Append(1);
            //    Console.WriteLine(str2[random.Next(str2.Length)]);
            //}

            string str = new string(Enumerable.Repeat(str2, 8).Select(s => s[random.Next(s.Length)]).ToArray());
            //Enumerable.Repeat(str2, 8) 将str2字符串生成8次 
            //

            Console.WriteLine(str);

            string[] colors = { "red", "green", "blue", "yellwo", "black" };
            string color = colors[random.Next(colors.Length)];

            Console.ReadKey();
        }
    }
}
